package com.gcd.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gcd.model.form.CourseOfMember;
import com.gcd.service.MyCoursesService;
import com.gcd.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/v1/myCourse",produces = MediaType.APPLICATION_JSON_VALUE)
public class MyCoursesApi {
    private MyCoursesService myCoursesService;

    @Autowired
    public void setMyCoursesService(MyCoursesService myCoursesService) {
        this.myCoursesService = myCoursesService;
    }

    //获取预约个人课程
    @GetMapping
    public ResponseEntity<JsonResult<?>> getMyCourses(@RequestAttribute("userId") Integer memberId,
                                                      @RequestParam(defaultValue = "1") Integer pageNo,
                                                      @RequestParam(defaultValue = "100") Integer pageSize, CourseOfMember courseOfMember) {
        Page<CourseOfMember> page=new Page<>(pageNo,pageSize);
        page=myCoursesService.getMyCourses(memberId,page,courseOfMember);
        return ResponseEntity.ok(JsonResult.success(page));
    }

    //取消个人预约
    @PutMapping("/changeReserve")
    public ResponseEntity<JsonResult<?>> changeReserve(@RequestBody CourseOfMember courseOfMember) {
        boolean result= myCoursesService.changeReserve(courseOfMember);
        if( result) {
            return ResponseEntity.ok(JsonResult.success(result));
        } else {
            return ResponseEntity.ok(JsonResult.fail("取消预约失败"));
        }
    }
}
